package com.example.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.Students;
import com.example.entity.StudentsVO;
import com.example.service.StudentManageService;

@RequestMapping("manage")
@RestController
public class StudentManageController {
    @Autowired
    private StudentManageService studentManageService;
    
    /**
	 * 修改用户
	 * @param id
	 * @return
	 */
	@RequestMapping(path = "/upwlstudents")
	public Map<String, Object> upwlstudents(Students students) { // 受影响的行数 
		int rows = studentManageService.upwlstudent(students);
		Map<String, Object> rsMap =new HashMap<String, Object>();
		rsMap.put("code", rows > 0 ? "0" : "1");
		rsMap.put("msg", rows > 0 ? "删除成功" : "删除失败");
		return rsMap;

	}
	
	
	
	
	/**
	 * 手动批量分配
	 */
	@PostMapping("/upstudentmanage")
	public Map<String, Object> upstudentmanage(StudentsVO studentsVO){
		
		int rows = studentManageService.upstudentmanage(studentsVO);
		Map<String, Object> rsMap =new HashMap<String, Object>();
		rsMap.put("code", rows > 0 ? "0" : "1");
		rsMap.put("msg", rows > 0 ? "分配成功" : "分配失败");
		return rsMap;
	}
     
	
	/**
	 * 网络学生的多条件查询
	 * @param StudentsVO
	 * @return
	 */
	@RequestMapping("/findStudentmanage")
	public Map<String, Object> findStudentmanage(StudentsVO studentsVO){
		Map<String, Object> reMap=new HashMap<String, Object>();
		studentsVO.setOffset((studentsVO.getPage()-1)*studentsVO.getLimit());
		List<Students> list=studentManageService.findStudents(studentsVO);
		int count=studentManageService.getCountStudents(studentsVO);
		reMap.put("code","0");
		reMap.put("msg", "success");
		reMap.put("count", count);
		reMap.put("data", list);
		return reMap;
	}
}
